package journal

import "sync"

var (
	_globalLogger ILogger
	_globalLock   sync.RWMutex
)

type ILogger interface {
	With(fields ...Field) ILogger
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)
	Panic(msg string, fields ...Field)
}

func ReplaceGlobals(logger ILogger) func() {
	_globalLock.Lock()
	defer _globalLock.Unlock()
	prev := _globalLogger
	_globalLogger = logger
	return func() {
		ReplaceGlobals(prev)
	}
}

func L() ILogger {
	_globalLock.RLock()
	defer _globalLock.RUnlock()
	return _globalLogger
}
